package com.qk.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.qk.common.constant.CacheConstants;
import com.qk.domain.business.BusinessCountDO;
import com.qk.domain.clue.ClueCountDO;
import com.qk.management.aop.anno.CacheAble;
import com.qk.management.mapper.BusinessMapper;
import com.qk.management.mapper.ClueMapper;
import com.qk.management.service.ReportOverviewService;
import com.qk.vo.portal.PortalVO;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author: Enid
 * @date: 2025/10/16 14:53
 * @description: 首页数据概览的业务层实现类
 */
@Slf4j
@Service
@SuppressWarnings("all")
public class ReportOverviewServiceImpl implements ReportOverviewService {
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private StringRedisTemplate redisTemplate;
    //缓存的key前缀,用:连接
    private static final String CACHE_PORTAL_KEY_PREFIX = "qk:portal:";

    @CacheAble(
            KeyPrefix = CacheConstants.CACHE_PORTAL_KEY_PREFIX,
            ExpireTime = 24 * 60L,
            timeUnit = TimeUnit.HOURS
    )
    @Override
    public PortalVO reportOverviewWithCache() {
        ClueCountDO clueCountDO = clueMapper.selectCountClue();
        BusinessCountDO businessCountDO = businessMapper.selectCountBusiness();
        PortalVO vo = BeanUtil.copyProperties(clueCountDO, PortalVO.class);
        BeanUtil.copyProperties(businessCountDO, vo);
        return vo;
    }
}
